package com.y2.authprj.bean.auth.model;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.gdglc.spring.biz.auth.FunctionauthorityBiz;
import com.y2.authprj.dao.auth.IFunctionauthorityDao;

/**
 * 获取权限名称
 * @author zwt
 *
 */
public class AuthorCheck {

	private FunctionauthorityBiz biz; 
 	
	public AuthorCheck(){
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		this.biz = (FunctionauthorityBiz)context.getBean("functionBiz");
	}

	/**
	 * 在注释总调用该方法获取权限名称，用于反射是和
	 * session中的staff的权限对比实现请权限验证
	 * @param name
	 * @return info.getName() 主要起到key的作用
	 */
	public String getFunctionIdByName(String name){
		List<FunctionauthorityInfo> infos = biz.findAll();
		for(FunctionauthorityInfo info:infos){
			if(info.getName().equals(name)){
				return String.valueOf(info.getFunctionauthorityId());
			}
		}
		return null;
	}
	
	/**
	 * 根据staffId查询该用户所属角色的所有functionauthorityid，
	 * 用于和当前用户操作的调用的方法上的注解的value()方法返回值进行对比
	 * @param staffId
	 * @return
	 */
	public List<String> getFunctionauthorityIdByStaffId(String staffId){
		List<String> functionauthorityIdList = biz.getAllFunctionauthorityIdByStaffId(staffId);
		if(functionauthorityIdList!=null){
			return functionauthorityIdList;
		}else{
			return null;
		}	
	}
}
